#ifndef ALARMMODEL_H
#define ALARMMODEL_H

#include <QAbstractListModel>
#include <QDateTime>

struct Alarm {
    QString id;
    QString stationId;
    QString message;
    QString severity; // "warning", "critical"
    QDateTime timestamp;
    bool acknowledged;
    
    // 基站详细信息（告警时的快照）
    QString stationName;
    double latitude;
    double longitude;
    double signalStrength;
    int connectedUsers;
    QString status;
};

class AlarmModel : public QAbstractListModel
{
    Q_OBJECT

public:
    enum Roles {
        IdRole = Qt::UserRole + 1,
        StationIdRole,
        MessageRole,
        SeverityRole,
        TimestampRole,
        AcknowledgedRole,
        StationNameRole,
        LatitudeRole,
        LongitudeRole,
        SignalStrengthRole,
        ConnectedUsersRole,
        StatusRole
    };

    explicit AlarmModel(QObject *parent = nullptr);

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QHash<int, QByteArray> roleNames() const override;

    Q_INVOKABLE void acknowledgeAlarm(int index);
    Q_INVOKABLE void clearAll();
    Q_INVOKABLE int unacknowledgedCount() const;
    Q_INVOKABLE QVariantMap getAlarmInfo(int index) const;
    Q_INVOKABLE int getTotalCount() const;
    Q_INVOKABLE int getCountByStation(const QString &stationId) const;

public slots:
    void addAlarm(const QString &stationId, const QString &message, const QString &severity);
    void addAlarmWithDetails(const QString &stationId, const QString &message, const QString &severity,
                            const QString &stationName, double latitude, double longitude,
                            double signalStrength, int connectedUsers, const QString &status);

signals:
    void newAlarmAdded(const QString &stationId, const QString &message, const QString &severity);

private:
    QList<Alarm> m_alarms;
    int m_nextId;
};

#endif // ALARMMODEL_H

